//订单管理-订单售后-运单填写
App.util.ns('Admin.Orders.AfterSale');
Admin.Orders.AfterSale.Deliversno = function(dataTable){
    var win = new App.Win({
        name: 'deliversno',
        title: '换货运单',
        width: '720px'
    });

    //表单提交
    var form = new App.Form({
        items: [
            {type: 'hidden', name: 'order_id'},
            {type: 'selectLists', name: 'deliver_code', title: '快递字母简称', required: true,
                data_id: 'id', 
                data_name: function(item){
                    return item.code+':'+item.name;
                },
                dataTable: {
                    baseUrl: '/admin/logistics/delivers',
                    dataUrl: 'lists',
                    data_id: 'id',
                    data_name: 'name',
                    table: {
                        id: 'id',
                        main: 0,
                        columns: (function(){
                            return App.util.copy(Admin.Logistics.Delivers.Conf.columns);
                        })()
                    },
                    filter: [
                        {type: 'keywords'},
                        {type: 'timeRange'}
                    ],
                    height: '720px'
                }
            },
            {type: 'input', name: 'deliver_no', title: '快递单号', required: true, rule: {
                type: 'str',
                range: [6, 100]
            }}
        ]
    });
    form.fix(win.contentContainer);
    win.form = form;
    win.changeAftersale = function(aftersale){
        win.aftersale = aftersale;
        return win;
    };

    //设置按钮
    win.setBtns([(function(){
        var cancelBtn = $('<a class="btn btn-danger btn-xs m-right-sm">取消</a>');
        cancelBtn.click(function(){
            win.hide();
        });
        return cancelBtn;
    })(), (function(){
        var saveBtn = $('<a class="btn btn-success btn-xs">提交</a>');
        saveBtn.click(function(){
            var formData = form.getData();
            App.util.request.postData({
                url: '/admin/orders/aftersale/createlogistics',
                data: {
                    order_id: formData['order_id'],
                    deliver_code: formData['deliver_code'],
                    deliver_no: formData['deliver_no']
                },
                loading: new App.Loading(win.contentContainer),
                success: function(){
                    App.util.hint.toast({
                        type: 'ok',
                        text: '提交成功'
                    }).delay(500, function(){
                        win.hide();
                    });
                }
            });
        });
        return saveBtn;
    })()]);
    win.hide();
    return win;
};